package com.hyq.learn.api.rest;

import com.hyq.learn.common.exception.InternalServiceException;
import com.hyq.learn.common.exception.SvcException;
import com.hyq.learn.common.exception.errorcode.CommonErrorCode;
import com.hyq.learn.common.exception.errorcode.ErrorCode;
import com.hyq.learn.common.response.CommonResponse;
import org.springframework.web.bind.annotation.*;

/**
 * 测试异常处理相关功能
 *
 * @author heyuqin
 * @date 2024/6/27 17:48
 */
@RequestMapping("exception")
@RestController
public class ExceptionTestController {

    @PostMapping("test/{num}")
    public CommonResponse<String> testExceptionHandler(@PathVariable("num") Integer num) {
        if (num == 1) {
            throw new RuntimeException("runtime exception");
        }
        if (num == 2) {
            throw new SvcException(CommonErrorCode.INTERNAL_ERROR, "svc exception");
        }
        if (num == 3) {
            throw new InternalServiceException("Internal service exception");
        }
        return CommonResponse.success("success");
    }
}
